/**
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
** \file DataSet.h
** \version $Id: DataSet.h 25 2009-10-28 16:17:47Z rigdern $
*/

#ifndef _DATASET_H
#define _DATASET_H

#include "BasicAttribute.h"
#include <common/sqlite/sqlite3.h>
#include <common/utilities/DistanceVector.h>
#include <vector>
#include <stdexcept>

class database_error : public std::runtime_error
{
public:
  explicit database_error(const std::string& arg);
};

class DataSet
{
public:
  DataSet(sqlite3* database, std::vector<BasicAttribute*> attributes);
  ~DataSet();
  
  DistanceVector maximalVector() const;

  int suppressionsForGeneralization(const DistanceVector& distanceVector, unsigned int k) const;
  bool satisfies(const DistanceVector& distanceVector, unsigned int k, unsigned int maxSup) const;
  void dumpGeneralizedTable(const DistanceVector& distanceVector, unsigned int k) const;
  void dumpGeneralizationTable() const;
  
private:
  sqlite3* _database;
  std::vector<BasicAttribute*> _attributes;
  
  void constructGeneralizationTable();
  std::string columnList(DistanceVector distanceVector) const;
  void dumpQueryResult(const char* query) const;
  
  friend void sqlfnGeneralizedValue(sqlite3_context *context, int huh, sqlite3_value **value);
};

#endif
